/**
 *  a class which represent an attachment of a single value to a single variable. implement assignment.
 * @author Nadav Cohen, Matan Monitz
 *
 */
public class ValueAssignment implements Assignment{
	
	private Variable var;    // field represent a single variable (object which implements interface Variable)
	private double 	 value;  // field represent a real number which is the value of variable var 

	
/**
 * Constructor Method - 
 * Constructor will copy the pointer to the already existing Variable var (shallow copy).
 * will throw runtimeException in case parameter var is not valid. 
 * @param var - object which represnt a single Variable.
 * 				valid only if truly exist - pointer points to an existing object (not null).
 * @param value - a real number which will be the value of the Variable var.
 */
	public ValueAssignment(Variable var,double value) {
		if(var!=null){
			this.var=var;		//copy the pointer to the already existing Variable var (shallow copy)
			this.value=value;
		}
		else
			throw new RuntimeException("cannot build ValueAssignment since Variable given not initialzed!");
	
	}


/**
 * Equals Method-
 * compare parameter Object other to this ValueAssignment. Objects Equals if:
 * - parameter other is type ValueAssignment  and not null
 * - parameter other variable is the same variable as this object.
 * - parameter other value (Hasama) is the same value as this object.
 *  @return true if equals, else return false.
 */
	public boolean equals(Object other) {
		boolean ans = false;
		if(other instanceof ValueAssignment)
		{
			ans = (((ValueAssignment) other).getValue()==this.value && ((ValueAssignment)other).getVar()==this.var);
		}
		
		return ans;
	}
	
	

	public String toString(){
		return var.toString()+"="+value;
	}
	
	
	public Variable getVar() {
		return var;
	}
	
	public double getValue() {
		return value;
	}
	
	public void  setValue(double value) {
		this.value = value;
	}
	
	
	

}
